<template>
  <div class="singer-item">
    <div class="left e_1">
      {{ item.name }}
      <span v-for="(ar, index) in item.alias" :key="index">({{ ar }})</span>
    </div>
    <div class="right" :class="{ active: isFollow }">
      <span v-if="isFollow" @click.stop="removeFollowSinger({ id: item.id })">
        √已关注</span
      >
      <span v-else @click.stop="addFollowSinger({ id: item.id })"> + 关注</span>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  name: "SingerItem",
  props: {
    item: Object,
  },
  computed: {
    ...mapState(["followSingers"]),

    // 检查是否关注这个歌手
    isFollow() {
      return this.followSingers.includes(this.item.id);
    },
  },

  methods: mapMutations(["addFollowSinger", "removeFollowSinger"]),
};
</script>

<style lang="less" scoped>
.singer-item {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;

  .left {
    flex: 1;
    padding-left: 20px;

    span {
      color: #707070;
      font-size: 14px;
    }
  }

  :last-of-type {
    margin-bottom: 0;
  }

  .right {
    height: 60%;
    color: skyblue;
    border: 1px solid skyblue;
    border-radius: 10px;
    line-height: 30px;

    span {
      padding: 10px;
      font-size: 14px;
    }

    &.active {
      color: #707070;
      border: 1px solid #707070;
      transition: 1s;
    }
  }
}
</style>
